// 封装 WebSocket 流式发送
export function sendMessageStream(model, message, sessionId, onChunk) {
  return new Promise((resolve, reject) => {
    const ws = new WebSocket(`ws://127.0.0.1:8000/ws/chat?session_id=${sessionId}`)

    ws.onopen = () => {
      ws.send(JSON.stringify({ model, message }))
    }

    ws.onmessage = (event) => {
      onChunk(event.data)
    }

    ws.onclose = () => resolve()
    ws.onerror = (err) => reject(err)
  })
}
